<template>
  <div class="hello">
    <el-table :data="tableData" style="width: 100%" max-height="250">
      <el-table-column fixed prop="id" label="图书ID" width="150"> </el-table-column>
      <el-table-column prop="title" label="图书" width="150"> </el-table-column>
      <el-table-column prop="author" label="作者" width="120"> </el-table-column>
      <el-table-column prop="copies" label="复印份数" width="120"> </el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button @click.native.prevent="$store.commit('deleteRow', scope.$index)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <p>现有图书：{{bookCount}}本</p>
    <el-button type="text" size="small">
      <router-link to="/add">添加书本</router-link>
      <router-view></router-view>
    </el-button>
  </div>
</template>

<script>
import { mapState, mapMutations, mapActions, mapGetters } from "vuex";

export default {
  computed: {
    ...mapState(["tableData"]), // 将 tableData 映射为计算属性
    ...mapGetters(["bookCount"]), // 将 bookCount 映射为计算属性
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
